import { ref } from 'vue';
import { defineStore } from 'pinia';

export const useKeepAlive = defineStore('keepAlive', () => {
  const includes = ref([]);

  const addItem = (item) => {
    if (!item) {
      return;
    }

    if (includes.value.indexOf(item) <= 0) {
      includes.value.push(item);
    }
  };

  const delItem = (item) => {
    if (!item && includes.value.length === 0) {
      return;
    }

    includes.value = includes.value.filter(include => include !== item);
  };

  const resetItems = (items) => {
    includes.value = items || [];
  };

  return {
    includes,
    addItem,
    delItem,
    resetItems
  };
});
